package cn.middle.edge.portal;

import java.util.Date;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.middle.common.result.ApiResponse;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.middle.edge.dto.DoorEvent;
import cn.middle.remote.edge.EdgeClient;

@Controller
@RequestMapping("/doorEvent")
public class DoorEventController {

	@Autowired
	private EdgeClient edgeClient;
	
	@SaCheckLogin
	@ResponseBody
	@GetMapping("/openDoor")
	public ApiResponse<Boolean> event(){
		DoorEvent event = new DoorEvent();
		event.setUsername("张三");
		event.setDescribe("张三进入XXX门禁设备");
		event.setEventId(UUID.randomUUID().toString());
		event.setEventType(1);
		event.setTriggerTime(new Date());
		//推送事件到平台
		edgeClient.event(100, UUID.randomUUID().toString(), event);
		return ApiResponse.successWithData(true);
	}
}
